<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>canvas01</title>
    <style>
        body{
            margin: 0;
            padding: 0;
            background: pink;
        }
        #cc{
            background: gray;
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
            top: 0;
            margin: auto;
        }
    
    </style>
</head>
<body>
    <canvas id="cc" width="300px" height="300px"></canvas>
    <script>
        window.onload=function(){
            // 获取画布元素；
            var cc=document.querySelector("#cc");
            if(cc.getContext){
                var ctx= cc.getContext("2d");
                ctx.arc(100,100,100,0,2*Math.PI);
                ctx.fill();
                // var dataURL = cc.toDataURL();
                // console.log(dataURL);

                cc.onclick=function(ev){
                    var x=ev.clientX-cc.offsetLeft;
                    var y=ev.clientY-cc.offsetTop;
                    if(ctx.isPointInPath(x,y)){

                    alert("hello");
                    }
                }
            }
            
        }
    </script>
</body>
</html>